<!DOCTYPE html>
<!--
/*******************************************************************************
#      ____               __          __  _      _____ _       _               #
#     / __ \              \ \        / / | |    / ____| |     | |              #
#    | |  | |_ __   ___ _ __ \  /\  / /__| |__ | |  __| | ___ | |__   ___      #
#    | |  | | '_ \ / _ \ '_ \ \/  \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \     #
#    | |__| | |_) |  __/ | | \  /\  /  __/ |_) | |__| | | (_) | |_) |  __/     #
#     \____/| .__/ \___|_| |_|\/  \/ \___|_.__/ \_____|_|\___/|_.__/ \___|     #
#           | |                                                                #
#           |_|                 _____ _____  _  __                             #
#                              / ____|  __ \| |/ /                             #
#                             | (___ | |  | | ' /                              #
#                              \___ \| |  | |  <                               #
#                              ____) | |__| | . \                              #
#                             |_____/|_____/|_|\_\                             #
#                                                                              #
#                              (c) 2010-2011 by                                #
#           University of Applied Sciences Northwestern Switzerland            #
#                     Institute of Geomatics Engineering                       #
#                           martin.christen@fhnw.ch                            #
********************************************************************************
*     Licensed under MIT License. Read the file LICENSE for more information   *
*******************************************************************************/

                  TUTORIAL 7.2: Playing Video in a billboard object
*******************************************************************************/
-->
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="../../../external/closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../../../compiled/deps.js"></script>
<script type="text/javascript">goog.require('owg.OpenWebGlobe');</script>

<script type="text/javascript">

var billboard_id;
var billboardlayer;
var video = null;



//------------------------------------------------------------------------------
// called every frame:
function OnRender(context)
{
   // important: we need this to update the video billboard.
   ogUpdateBillboard(billboard_id,video);
}

//------------------------------------------------------------------------------
// Mouse-Down-Event: Called when a mouse button is pressed
function OnMouseDown(context, button, mx, my)
{

   // retrieve the scene attached to context:
   var scene = ogGetScene(context);
   var coors = ogPickBillboard(scene,mx,my);
   
   if(coors)
   {
      console.log(" x: "+coors.x+" y: "+coors.y);
   }
   
}

//------------------------------------------------------------------------------
function main()
{
   // (0) Set location of Artwork directory. Because of CORS this can't be local
   // if you want to open this using file://...
   ogSetArtworkDirectory("http://www.openwebglobe.org/art/");
   
   // (1) create an OpenWebGlobe context using canvas
   // first parameter is canvas-id and second is "fullscreen"
   var ctx = ogCreateContextFromCanvas("canvas", true);
   
   // (2) Create a virtual globe
   var globe = ogCreateGlobe(ctx);
   
   // (3) Add an image and an elevation layer
   
   var imgBlueMarble500 = 
   {
      url     : ["http://www.openwebglobe.org/data/img"],
      layer   : "World500",
      service : "i3d"
   };
   
   var elvSRTM_CH = 
   {
      url     : ["http://www.openwebglobe.org/data/elv"],
      layer   : "SRTM",
      service : "i3d"
   };
   
   ogAddImageLayer(globe, imgBlueMarble500);
   ogAddElevationLayer(globe, elvSRTM_CH);

   // (4) Set the "Render-Callback" function.
   // The callback function will be called everytime a frame is drawn.
   ogSetRenderFunction(ctx, OnRender);
   
   // (5) Set the background color
   ogSetBackgroundColor(ctx, 0.2,0.2,0.7,1);
   
   // (6) Set the mouse down function. We need this for picking!
   ogSetMouseDownFunction(ctx, OnMouseDown);
   
   // (7) get the scenen
   var scene = ogGetScene(ctx);
   
   // (8) create the Billboard Layer
   var world = ogGetWorld(scene);
   billboardlayer = ogCreateBillboardLayer(world,"billboards");
   
   
   //(9)  create the HTML5 Video element
   video = document.createElement('video');
   video.controls = false;   
   video.src = "video.ogv"; //set your ogv video here...
   video.autoplay="true";
   
   //when the video is loaded create a billboard.
   video.onloadeddata = function()
                  {
                     billboard_id = ogCreateBillboardFromCanvas(billboardlayer,video,7.569964,46.135222,5735);
                  }
  
}

//------------------------------------------------------------------------------
   
</script>

</head>
<body onload="main()" style="padding:0px; margin:0px; overflow:hidden;">
   <div style="text-align: center">
   <canvas id="canvas"></canvas>
   </div>
</body>
</html>
